﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace xuyiying
{
    public partial class frmTeacherAdd : Form
    {
        public frmTeacherAdd()
        {
            InitializeComponent();
        }

        private void frmTeacherAdd_Load(object sender, EventArgs e)
        {
            SqlOperate obj = new SqlOperate();
            string strSql = "select crouseName from T_crouse";
            SqlDataReader odr = obj.GetDR(strSql);
            while (odr.Read())
            {

                comboBox1.Items.Add(odr.GetValue(0).ToString());
            }
            comboBox1.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String sex="";
            if (radioButton1.Checked)
            {
                sex = "男";
            }
            else
            {
                sex = "女";
            }
            SqlOperate obj = new SqlOperate();
            string strSql = "insert into T_teacher(sex,TeacherName,Teaching) values('" + sex + "','" + textBox1.Text + "','"+comboBox1.Text+"')";
            if (obj.RunSql(strSql) > 0)
            {
                MessageBox.Show("添加记录成功！", "信息提示", MessageBoxButtons.OK);
                DataGridViewRow row = new DataGridViewRow();
                int index = dataGridView1.Rows.Add(row);
                dataGridView1.Rows[index].Cells[0].Value = sex;
                dataGridView1.Rows[index].Cells[1].Value = textBox1.Text;

                textBox1.Text = "";
               
                textBox1.Focus();
            }
            else
            { MessageBox.Show("添加记录失败！", "信息提示", MessageBoxButtons.OK); }
        }
    }
}
